import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @User: vitobo
 * @Date: 2024-09-04
 * @Description:
 */

@WebServlet("/getParameter")
public class GetParameterServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 预期 浏览器会发一个形如 /getParameter?studentId=10&classId=20请求
        // 借助req中的getParameter方法, 就能拿到query string 中的键值对内容了
        // getParameter得到的是 String类型的结果
        String studentId = req.getParameter("studentId");
        String classId = req.getParameter("classId");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf8");

        resp.getWriter().write("studentId= " + studentId + " classId= " + classId);
    }
}
